*---------------------------------------------------------------
*---------------------------------------------------------------
* This code base replicates sampling diagnoistics reported in 
* Figures A5 and A6
*---------------------------------------------------------------
*---------------------------------------------------------------

clear all

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* To manually run file, set the working directory below *
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

cd "~/Dropbox/Historical Displacement and Ethnicity - Afghanistan/REPOSITORY"

*---------------------------------------------------------------
* Section 1: Load and define variables in sampling diagnoistics 
*---------------------------------------------------------------

use "replication/data/input/FOGHORN_sampling.dta", clear

* village_count = number of villages in given grid cell (count)
* sampled = indicates whether survey sampling was present during FOGHORN sample waves (=1)
* ethnic_triple = language category, which captures ethnic identity (=1 if Pashto, =2 if Dari, =0 otherwise)
* village_dist = grid cell within mass of village density distribution (at or below 95th percentile)

*---------------------------------------------------------------
* Section 2: Make Figure A5
*---------------------------------------------------------------
	
tw ///
	(kdensity village_count if ethnic_triple==0, yaxis(1) lcolor(green%50) lpattern(solid)) ///
	(kdensity village_count if ethnic_triple==1, yaxis(1) lcolor(blue%50) lpattern(solid)) ///
	(kdensity village_count if ethnic_triple==2, yaxis(1) lcolor(red%50) lpattern(solid)) ///
	(kdensity village_count if ethnic_triple==0&sampled==1, yaxis(1) lcolor(green) lpattern(dash)) ///
	(kdensity village_count if ethnic_triple==1&sampled==1, yaxis(1) lcolor(blue) lpattern(dash)) ///
	(kdensity village_count if ethnic_triple==2&sampled==1, yaxis(1) lcolor(red) lpattern(dash)), ///
	title(Characteristics of sampled villages relative to sampling frame) ///
	ytitle(Density of villages across grid cells, axis(1)) ///
	xtitle(Number of villages within grid cluster) ///
	legend(title("Language of grid cluster", size(small)) ring(0) pos(1) col(1) order(1 "Other (Overall)" 2 "Pashto (Overall)" 3 "Dari (Overall)" 4 "Other (Sampled)" 5 "Pashto (Sampled)" 6 "Dari (Sampled)") size(small) symxsize(*.5)) 
	
graph export "replication/results/figures/FigureA5.jpg", as(jpg) name("Graph") quality(90) replace

*---------------------------------------------------------------
* Section 3: Make Figure A6
*---------------------------------------------------------------
	
tw ///
	(lpolyci sampled village_count if ethnic_triple==0&village_dist==1, yaxis(1) ciplot(rline) nofit lcolor(red%50) lpattern(solid)) ///
	(lpolyci sampled village_count if ethnic_triple==1&village_dist==1, yaxis(1) ciplot(rline) nofit lcolor(blue%50) lpattern(solid)) ///
	(lpolyci sampled village_count if ethnic_triple==2&village_dist==1, yaxis(1) ciplot(rline) nofit lcolor(green%50) lpattern(solid)) ///
	(lpolyci sampled village_count if village_dist==1, yaxis(1) ciplot(rline) nofit  lcolor(black%50) lpattern(solid)), ///
	title(Characteristics of sampled villages relative to sampling frame) ///
	ytitle(Likelihood of sampling) xtitle(Number of villages within grid cluster) ///
	legend(title("Language of grid cluster", size(small)) ring(0) pos(10) col(1) order(1 "Other" 2 "Pashto" 3 "Dari" 4 "Overall") size(small) symxsize(*.5)) 
	
graph export "replication/results/figures/FigureA6.jpg", as(jpg) name("Graph") quality(90) replace
	